﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.IO;

namespace website
{
    public partial class Default : System.Web.UI.Page
    {
        Socket socket;
        protected void Page_Load(object sender, EventArgs e)
        {
            var datas = Request["postdata"];
            if (IsPostBack)
            {
                //todo:将命令段集成至文件服务器
                //转换文件命令格式: officeconvert|e://file/abc.doc|d://filefolder/flash/|1  
                //1:表示只转换为pdf文件0或者不加表示flash
                string commend = Request["txtcmd"];
                TcpClient client = new TcpClient("42.121.107.168", 23456);
                socket = client.Client;
                byte[] buffer = Encoding.UTF8.GetBytes(commend);
                socket.Send(buffer);
                byte[] data = new byte[2048];
                socket.Receive(data);
                string req = Encoding.UTF8.GetString(data);
                req = req.Substring(0, req.IndexOf("\0"));
                var result = req.Split('|');
                if (result[0]=="result")
                {
                    Session["file"] = Path.GetFileName(result[1]);
                    Response.Write("文件已生成！："+result[1]);
                }
                else if (result[0]=="msg")
                {
                    Response.Write(result[1]);
                }
                else
                {
                    Response.Write(result[0]);
                }
            }
        }
    }
}